@@ -53,6 +53,7 @@ gem 'fog' |
||
53 | 53 |
gem "carrierwave" |
54 | 54 |
gem 'i18n' |
55 | 55 |
gem 'rails_12factor', group: :production |
56 |
+gem 'gibbon' |
|
56 | 57 |
|
57 | 58 |
group :test do |
58 | 59 |
gem "rspec" |
@@ -117,7 +117,13 @@ GEM |
||
117 | 117 |
activerecord (>= 4.0.0) |
118 | 118 |
gherkin (2.12.2) |
119 | 119 |
multi_json (~> 1.3) |
120 |
+ gibbon (1.1.4) |
|
121 |
+ httparty |
|
122 |
+ multi_json (>= 1.3.4) |
|
120 | 123 |
hike (1.2.3) |
124 |
+ httparty (0.13.3) |
|
125 |
+ json (~> 1.8) |
|
126 |
+ multi_xml (>= 0.5.2) |
|
121 | 127 |
i18n (0.6.11) |
122 | 128 |
inflecto (0.0.2) |
123 | 129 |
ipaddress (0.8.0) |
@@ -149,6 +155,7 @@ GEM |
||
149 | 155 |
minitest (4.7.5) |
150 | 156 |
multi_json (1.10.1) |
151 | 157 |
multi_test (0.1.1) |
158 |
+ multi_xml (0.5.5) |
|
152 | 159 |
net-scp (1.2.1) |
153 | 160 |
net-ssh (>= 2.6.5) |
154 | 161 |
net-ssh (2.9.1) |
@@ -273,6 +280,7 @@ DEPENDENCIES |
||
273 | 280 |
fog |
274 | 281 |
font-awesome-rails |
275 | 282 |
friendly_id (~> 5.0.0) |
283 |
+ gibbon |
|
276 | 284 |
i18n |
277 | 285 |
jasny_bootstrap_extension_rails |
278 | 286 |
jbuilder (~> 1.2) |
@@ -1,7 +1,11 @@ |
||
1 | 1 |
class Subscription < ActiveRecord::Base |
2 | 2 |
|
3 |
+ after_create do |
|
4 |
+ subscribe_to_mailchimp |
|
5 |
+ end |
|
6 |
+ |
|
3 | 7 |
def full_name |
4 |
- return self.first_name + " " + self.last_name |
|
8 |
+ return self.first_name.to_s + " " + self.last_name.to_s |
|
5 | 9 |
end |
6 | 10 |
|
7 | 11 |
def self.to_csv |
@@ -13,4 +17,15 @@ class Subscription < ActiveRecord::Base |
||
13 | 17 |
end |
14 | 18 |
end |
15 | 19 |
|
20 |
+ def subscribe_to_mailchimp testing=false |
|
21 |
+ return true if (Rails.env.test? && !testing) |
|
22 |
+ list_id = ENV['MAILCHIMP_LIST_ID'] |
|
23 |
+ response = Rails.configuration.mailchimp.lists.subscribe({ |
|
24 |
+ id: list_id, |
|
25 |
+ email: {email: email}, |
|
26 |
+ double_optin: false, |
|
27 |
+ }) |
|
28 |
+ response |
|
29 |
+ end |
|
30 |
+ |
|
16 | 31 |
end |
@@ -16,4 +16,14 @@ class User < ActiveRecord::Base |
||
16 | 16 |
return name |
17 | 17 |
end |
18 | 18 |
|
19 |
+ after_create do |
|
20 |
+ subscribe_user |
|
21 |
+ end |
|
22 |
+ |
|
23 |
+ def subscribe_user |
|
24 |
+ if Subscription.find_by_email(self.email) == nil |
|
25 |
+ Subscription.create(first_name: self.first_name, last_name: self.last_name, email: self.email) |
|
26 |
+ end |
|
27 |
+ end |
|
28 |
+ |
|
19 | 29 |
end |
@@ -0,0 +1,6 @@ |
||
1 |
+if Rails.env.test? |
|
2 |
+ Gibbon::Export.api_key = "fake" |
|
3 |
+ Gibbon::Export.throws_exceptions = false |
|
4 |
+end |
|
5 |
+ |
|
6 |
+Rails.configuration.mailchimp = Gibbon::API.new(ENV['MAILCHIMP_KEY']) |